<template>
  <van-collapse v-model="activeName" accordion class="panel-grade-filter">
    <van-collapse-item title="高级查询" name="1" icon="filter-o">
      <van-field v-if="assessType === $vo.AssessType.CORP + '' && operateType === $vo.OperateType.GRADE" name="radio" style="padding: 10px 36px" label="查询范围：" input-align="center">
        <template #input>
          <van-row style="width: 100%; text-align: center">
            <van-radio-group v-model="scope" direction="horizontal">
              <van-col span="12">
                <van-radio name="0">按部门查询</van-radio>
              </van-col>
              <van-col span="12">
                <van-radio name="1">按科室查询</van-radio>
              </van-col>
            </van-radio-group>
          </van-row>
        </template>
      </van-field>
      <van-cell>
        <van-dropdown-menu>
          <van-dropdown-item v-model="carrier" :options="carrierOption" />
          <van-dropdown-item v-model="status" :options="statusOption" />
        </van-dropdown-menu>
      </van-cell>
      <van-cell style="text-align: center">
        <van-button size="small" block type="primary" @click="doClick">查询</van-button>
      </van-cell>
    </van-collapse-item>
  </van-collapse>
</template>

<script>
import { getCarrierList } from '@/api/assess'
export default {
  name: 'PanelGradeFilter',
  props: ['assessType', 'operateType'],
  data () {
    return {
      activeName: '',
      carrier: '',
      status: '',
      scope: '0',
      carrierOption: [
        { text: '全部载体', value: '' }
      ],
      statusOption: [
        { text: '全部考评', value: '' },
        { text: '待评分', value: '0' },
        { text: '待提交', value: '8' },
        { text: '待审核', value: '1' },
        { text: '审核通过', value: '2' },
        { text: '反馈待本部门审核', value: '3' },
        { text: '反馈待局领导复核', value: '4' },
        { text: '反馈待最终审核', value: '5' },
        { text: '反馈待修改', value: '6' },
        { text: '考评结束', value: '7' }
      ]
    }
  },
  mounted () {
    getCarrierList(this.$vo.CarrierType.SUB).then(res => {
      let { data } = res
      if (data[this.$response.CODE] === this.$response.SUCCESS) {
        let str = JSON.stringify(data[this.$response.DATA].check_list.sort(this.listSort)).replace(new RegExp('id', 'g'), 'value').replace(new RegExp('item', 'g'), 'text')
        this.carrierOption = this.carrierOption.concat(JSON.parse(str))
      }
    }, errFunc => {
      this.$notify('服务调用失败：' + errFunc.toString())
      console.log(errFunc.toString())
    })
  },
  methods: {
    doClick () {
      let condition = this.$vo.createCondition()
      condition.matters = this.carrier
      condition.problem_status = this.status
      condition.problem_type = this.assessType
      condition.scope = this.scope
      this.$emit('onQuery', condition)
    },
    listSort (obj1, obj2) {
      let val1 = Number(obj1.id)
      let val2 = Number(obj2.id)
      if (val1 < val2) {
        return -1
      } else {
        return 1
      }
    }
  }
}
</script>

<style scoped lang="less">
  .panel-grade-filter{
    .van-collapse-item{
      /deep/ .van-collapse-item__content{
        padding: 0px;
        .van-cell{
          font-size: 12px;
          line-height: 20px;
        }
      }
    }
    /deep/ .van-dropdown-menu__title{
      font-size: 12px;
    }

    /deep/ .van-dropdown-menu__bar {
      height: 40px;
    }
  }
</style>
